{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>id_str</th>\n",
       "      <th>user_location</th>\n",
       "      <th>user_bg_color</th>\n",
       "      <th>retweet_count</th>\n",
       "      <th>user_name</th>\n",
       "      <th>polarity</th>\n",
       "      <th>created</th>\n",
       "      <th>geo</th>\n",
       "      <th>user_description</th>\n",
       "      <th>user_created</th>\n",
       "      <th>user_followers</th>\n",
       "      <th>coordinates</th>\n",
       "      <th>subjectivity</th>\n",
       "      <th>text</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>729828033092149248</td>\n",
       "      <td>Wheeling WV</td>\n",
       "      <td>022330</td>\n",
       "      <td>0</td>\n",
       "      <td>Jaybo26003</td>\n",
       "      <td>0.00</td>\n",
       "      <td>2016-05-10T00:18:57</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2011-11-17T02:45:42</td>\n",
       "      <td>39</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>Make a difference vote! WV Bernie Sanders Coul...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>729828033092161537</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C0DEED</td>\n",
       "      <td>0</td>\n",
       "      <td>brittttany_ns</td>\n",
       "      <td>0.15</td>\n",
       "      <td>2016-05-10T00:18:57</td>\n",
       "      <td>NaN</td>\n",
       "      <td>18 // PSJAN</td>\n",
       "      <td>2012-12-24T17:33:12</td>\n",
       "      <td>1175</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.1</td>\n",
       "      <td>RT @HlPHOPNEWS: T.I. says if Donald Trump wins...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>729828033566224384</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C0DEED</td>\n",
       "      <td>0</td>\n",
       "      <td>JeffriesLori</td>\n",
       "      <td>0.00</td>\n",
       "      <td>2016-05-10T00:18:57</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-10-11T14:29:59</td>\n",
       "      <td>42</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>You have no one to blame but yourselves if Tru...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>729828033893302272</td>\n",
       "      <td>global</td>\n",
       "      <td>C0DEED</td>\n",
       "      <td>0</td>\n",
       "      <td>WhorunsGOVs</td>\n",
       "      <td>0.00</td>\n",
       "      <td>2016-05-10T00:18:57</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Get Latest Global Political news as they unfold</td>\n",
       "      <td>2014-02-16T07:34:24</td>\n",
       "      <td>290</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>'Ruin the rest of their lives': Donald Trump c...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>729828034178482177</td>\n",
       "      <td>California, USA</td>\n",
       "      <td>131516</td>\n",
       "      <td>0</td>\n",
       "      <td>BJCG0830</td>\n",
       "      <td>0.00</td>\n",
       "      <td>2016-05-10T00:18:57</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Queer Latino invoking his 1st amendment privil...</td>\n",
       "      <td>2009-03-21T01:43:26</td>\n",
       "      <td>354</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>RT @elianayjohnson: Per source, GOP megadonor ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   id              id_str    user_location user_bg_color  retweet_count  \\\n",
       "0   1  729828033092149248      Wheeling WV        022330              0   \n",
       "1   2  729828033092161537              NaN        C0DEED              0   \n",
       "2   3  729828033566224384              NaN        C0DEED              0   \n",
       "3   4  729828033893302272           global        C0DEED              0   \n",
       "4   5  729828034178482177  California, USA        131516              0   \n",
       "\n",
       "       user_name  polarity              created  geo  \\\n",
       "0     Jaybo26003      0.00  2016-05-10T00:18:57  NaN   \n",
       "1  brittttany_ns      0.15  2016-05-10T00:18:57  NaN   \n",
       "2   JeffriesLori      0.00  2016-05-10T00:18:57  NaN   \n",
       "3    WhorunsGOVs      0.00  2016-05-10T00:18:57  NaN   \n",
       "4       BJCG0830      0.00  2016-05-10T00:18:57  NaN   \n",
       "\n",
       "                                    user_description         user_created  \\\n",
       "0                                                NaN  2011-11-17T02:45:42   \n",
       "1                                        18 // PSJAN  2012-12-24T17:33:12   \n",
       "2                                                NaN  2012-10-11T14:29:59   \n",
       "3    Get Latest Global Political news as they unfold  2014-02-16T07:34:24   \n",
       "4  Queer Latino invoking his 1st amendment privil...  2009-03-21T01:43:26   \n",
       "\n",
       "   user_followers coordinates  subjectivity  \\\n",
       "0              39         NaN           0.0   \n",
       "1            1175         NaN           0.1   \n",
       "2              42         NaN           0.0   \n",
       "3             290         NaN           0.0   \n",
       "4             354         NaN           0.0   \n",
       "\n",
       "                                                text  \n",
       "0  Make a difference vote! WV Bernie Sanders Coul...  \n",
       "1  RT @HlPHOPNEWS: T.I. says if Donald Trump wins...  \n",
       "2  You have no one to blame but yourselves if Tru...  \n",
       "3  'Ruin the rest of their lives': Donald Trump c...  \n",
       "4  RT @elianayjohnson: Per source, GOP megadonor ...  "
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "tweets = pd.read_csv(\"~/Downloads/tweets.csv\")\n",
    "tweets.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "119998 30521\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEACAYAAACpoOGTAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFN5JREFUeJzt3X+s3fV93/HnK7i4kDBcJ5L5YfNDrZniinXBEc7aZbka\nlLpRB/wRgaOWsMbqH3U70k6LhjMpYFXqSqeKUk0gteGHYYVBISWgIGIHcrdUHRgSSCiGYqJZtc1s\nIhNgWbUOi/f+OB+Hk5vPte89/nHODc+HdHQ+53M+n6/f5xqf1/l+Pt9zSVUhSdJM7xl3AZKkyWRA\nSJK6DAhJUpcBIUnqMiAkSV0GhCSp65ABkeS2JPuSPDfU95+SvJDkW0m+mOTUoec2JtmR5MUklwz1\nr07yXHvupqH+xUnubf1PJDl76Lmrk7zUbp86ei9ZkjQXhzuDuB1YO6NvC/CzVfVzwEvARoAkq4Ar\ngVVtzs1J0ubcAqyvqpXAyiQHj7ke2N/6bwRuaMdaCnweuLDdrkuyZORXKUmat0MGRFV9HfjejL6t\nVfV2e/gksLy1LwPuqaq3qmon8DKwJsnpwClVta2NuxO4vLUvBTa39gPARa39S8CWqnq9ql4HtvKj\nQSVJOoaOdA/i08AjrX0GsHvoud3AmZ3+Pa2fdr8LoKoOAG8kef8hjiVJOk5GDogk/wH4f1V191Gs\nR5I0IRaNMinJvwY+zjtLQjA4M1gx9Hg5g0/+e3hnGWq4/+Ccs4BXkiwCTq2q/Un2AFNDc1YAj89S\ni79MSpLmqapyuDHzPoNoG8yfBS6rqv879NRDwLokJyY5F1gJbKuqvcCbSda0TeurgC8Nzbm6tT8B\nPNbaW4BLkixJ8lPALwJfmb2qGvMNqmrW23XXXXfI5yflZp3WOck36zx6t7k65BlEknuAjwEfSLIL\nuI7BVUs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QkqcuAkCR1GRCSpC4DQpLUZUBIkroMCElSlwEhSer6\n/1ihHJWUf01uAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x116092a20>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "trump                    119998\n",
      "clinton,trump             30521\n",
      "                          25429\n",
      "sanders                   25351\n",
      "clinton                   22746\n",
      "clinton,sanders            6044\n",
      "clinton,trump,sanders      4219\n",
      "trump,sanders              3172\n",
      "Name: candidate, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "def get_candidate(row):\n",
    "    candidates = []\n",
    "    text = row[\"text\"].lower()\n",
    "    if \"clinton\" in text or \"hillary\" in text:\n",
    "        candidates.append(\"clinton\")\n",
    "    if \"trump\" in text or \"donald\" in text:\n",
    "        candidates.append(\"trump\")\n",
    "    if \"sanders\" in text or \"bernie\" in text:\n",
    "        candidates.append(\"sanders\")\n",
    "    return \",\".join(candidates)\n",
    "\n",
    "tweets[\"candidate\"] = tweets.apply(get_candidate,axis=1)\n",
    "\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "%matplotlib inline\n",
    "\n",
    "counts = tweets[\"candidate\"].value_counts()\n",
    "plt.bar(range(len(counts)), counts)\n",
    "print(counts[0], counts[1])\n",
    "plt.show()\n",
    "\n",
    "print(counts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%magic"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
